package com.pzhu.user.domain.enums;

import com.fasterxml.jackson.annotation.JsonValue;
import com.mybatisflex.annotation.EnumValue;
import lombok.AllArgsConstructor;
import lombok.Getter;
import com.pzhu.base.common.utils.exceptions.BusinessException;

/**
 * 菜单类型
 *
 * @author liupeng221
 * @date 2024/03/28
 */
@AllArgsConstructor
@Getter
public enum MenuType {
    /**  菜单 */
    MENU(1, "MENU", "菜单"),
    /** 外链 */
    EXTERNAL_LINK(2, " EXTERNAL_LINK", "外链");

    /**
     * 类型
     */
    @EnumValue
    private final int type;

    /** 代码 */
    @JsonValue
    private final String code;

    /** desc */
    private final String desc;

    public static MenuType of(int type) {
        return switch (type) {
            case 1 -> MenuType.MENU;
            case 2 -> MenuType.EXTERNAL_LINK;
            default -> throw new BusinessException("菜单枚举不存在");
        };
    }
}
